package com.yyge.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyge.dto.R;
import com.yyge.entity.Employee;
import com.yyge.service.EmployeeService;
import com.yyge.vo.BeanConverter;
import com.yyge.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api("员工查询")
@RestController
@RequestMapping()
public class EmployeeController {
   //以前EmployeeService employeeService=new EmployeeServiceImpl();

    @Autowired
   private EmployeeService service;

   //以是 servlet 写法 doGet(HttpServletRequest,HttpServletResponse)  会动帮你转换成json
    @ApiOperation("员工查询-全查")
    @GetMapping(value = "/all" )
   public R searchAll () {
       return R.ok(this.service.list());
   }

   @ApiOperation("员工查询-分页查询")
   @GetMapping("/employee/data")
   public R findAll(Integer page,Integer size){
       //分页查询
       Page<Employee> info=new Page<>();
       //设置第几页 每页几条
       info.setCurrent(page);
       info.setSize(size);

       info = service.page(info);

       //将MP的分页对象转换未PageVO
       PageVo<Employee> vo= BeanConverter.MAPPER.page2vo(info);
       return R.ok(vo);
   }
}
